//
//  GameFunction.m
//  demo_3
//
//  Created by mac on 12-3-13.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "GameFunction.h"
#import "NGSNoodle.h"

@implementation GameFunction
-(int)trigger:(int)last{
    int i;
    lastNoodle=last;
        switch (lastNoodle) {
            case TYPE_NOODLE:
            {
                i = [self rollTheNext:TYPE_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_RADISH_NOODLE:
            {
                i = [self rollTheNext:INDEX_RADISH_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes: i];
                break;
            }
            case INDEX_CUCUMBER_NOODLE:
            {
                i = [self rollTheNext:INDEX_CUCUMBER_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_BEEF_NOODLE:
            {
                i = [self rollTheNext:INDEX_BEEF_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_MUTTON_NOODLE:
            {
                i = [self rollTheNext:INDEX_MUTTON_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_RADISH_BEEF_NOODLE:
            {
                i = [self rollTheNext:INDEX_RADISH_BEEF_NOODLE :success];
                //nextBowl=[OneBowl alloc];
               //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_CUCUMBER_MUTTON_NOODLE:
            {
                i = [self rollTheNext:INDEX_CUCUMBER_MUTTON_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_RADISH_MUTTON_NOODLE:
            {
                i = [self rollTheNext:INDEX_RADISH_MUTTON_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
            case INDEX_CUCUMBER_BEEF_NOODLE:
            {
                i = [self rollTheNext:INDEX_CUCUMBER_BEEF_NOODLE :success];
                //nextBowl=[OneBowl alloc];
                //[nextBowl setAttributes:i];
                break;
            }
                
            default:
                break;
    }
    return i;
}
-(int)rollTheNext:(int)lastT :(bool)lastS{
    int n_id=lastT;
    int up = (arc4random() % 10) + 1;
    int aim = (arc4random() % 10) + 1;
    int down = (arc4random() % 10) + 1;
    if(lastS)//上一把成功了
    {
        if (lastT%2==0) {//上一盘是偶数编号
            if (lastT!=INDEX_RADISH_MUTTON_NOODLE) {
                if (up>2) {
                    if(aim>6) n_id+=2;
                    else n_id+=3;
                }
                else{
                    if(aim>7){}
                    else {n_id+=1;}
                }
            }
        }
        else{//上一盘奇数
            if (lastT!=INDEX_CUCUMBER_BEEF_NOODLE) {
                if (up>2) {
                    if(aim>6) n_id+=2;
                    else n_id+=1;
                }
                else{
                    if(aim>7){}
                    else {n_id-=1;}
                }
            }
        }
    }
    else//上一把失败了
    {
        if(lastT!=INDEX_NOODLE)
        {
            if (lastT%2==0&&down>2){
                if(aim>6) n_id-=2;
                else n_id-=1;
            }
            else if(lastT%2==1&&down>2){
                if(aim>6) n_id-=2;
                else n_id-=3;
            }
            else{
                n_id-=5;
            }
        }
    }
    if(n_id>INDEX_CUCUMBER_BEEF_NOODLE)n_id=INDEX_CUCUMBER_BEEF_NOODLE;
    if(n_id<INDEX_NOODLE)n_id=INDEX_NOODLE;
    return n_id;
}



@end
